package org.geekbang.projects.injection.processor;

import org.geekbang.projects.injection.ApplicationContext;
import org.geekbang.projects.injection.BeanPostProcessor;
import org.geekbang.projects.injection.BeanWrapper;

/**
* 上下文通知后置处理器  
* @author : lsq
*/
public class ApplicationContextAwareBeanPostProcessor implements BeanPostProcessor {

	private ApplicationContext applicationContext;


	public ApplicationContextAwareBeanPostProcessor(ApplicationContext applicationContext){
		this.applicationContext = applicationContext;
	}

	@Override
	public void initializationBeforePostProcessor(BeanWrapper beanWrapper) {
		Object bean = beanWrapper.getBean();
		if (bean instanceof ApplicationContextAware){
			((ApplicationContextAware) bean).setApplicationContext(applicationContext);
		}
		if (bean instanceof EnvironmentAware){
			((EnvironmentAware) bean).setEnvironment(applicationContext.getEnvironment());
		}
	}

	@Override
	public void initializationPostProcessor(BeanWrapper beanWrapper) {

	}
}
